home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / BatD.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  7.3 KB  |  271 lines

  1. class classes.enemy.BatD
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var id;
  7.    var clip;
  8.    var colorR;
  9.    var trans;
  10.    var colorTrans;
  11.    var f2;
  12.    var dir;
  13.    var axis;
  14.    var xDest;
  15.    var yDest;
  16.    var oldDir;
  17.    var xMov = 0;
  18.    var yMov = 0;
  19.    var xMovT = 0;
  20.    var yMovT = 0;
  21.    var speedOrig = 8;
  22.    var speed = 8;
  23.    var xDestMet = false;
  24.    var yDestMet = false;
  25.    var c = 0;
  26.    var life = 2;
  27.    var nudging = false;
  28.    var nc = 0;
  29.    var xA = 0;
  30.    var yA = 0;
  31.    var power = 20;
  32.    var Name = "batD";
  33.    function BatD(px, py, pmoveScript, pid)
  34.    {
  35.       this.x = px;
  36.       this.y = py;
  37.       this.moveScript = pmoveScript.slice();
  38.       this.id = pid;
  39.       _root.d = _root.d + 1;
  40.       this.clip = _root.attachMovie("batB","batD" + this.id + "Clip",_root.d + 50000);
  41.       this.clip._x = this.x;
  42.       this.clip._y = this.y;
  43.       this.colorR = -255;
  44.       this.trans = new flash.geom.Transform(this.clip);
  45.       this.colorTrans = new flash.geom.ColorTransform(0,0,0,1,this.colorR,this.colorR,this.colorR,0);
  46.       this.trans.colorTransform = this.colorTrans;
  47.       this.speed *= _root.dif.speed;
  48.       this.speedOrig = this.speed;
  49.       this.life *= _root.dif.life;
  50.       this.speedVar();
  51.       this.parseMoveScript();
  52.       _root.stats.created = _root.stats.created + 1;
  53.    }
  54.    function bombed(num)
  55.    {
  56.       this.f2 = "death";
  57.    }
  58.    function nudge(pxA, pyA, pscale)
  59.    {
  60.       this.nc = 0;
  61.       this.nudging = true;
  62.       var _loc2_ = pscale / 100;
  63.       this.xA = pxA * _loc2_;
  64.       this.yA = pyA * _loc2_;
  65.    }
  66.    function speedVar()
  67.    {
  68.       if(random(3) == 1)
  69.       {
  70.          this.speed *= _root.randRange2(0.9999,1.0001);
  71.       }
  72.    }
  73.    function twist()
  74.    {
  75.       this.clip.body.gotoAndPlay("twist");
  76.    }
  77.    function parseMoveScript()
  78.    {
  79.       this.dir = this.moveScript[0];
  80.       if(this.dir == "break")
  81.       {
  82.          delete this.moveScript;
  83.          this[this.axis + "MovT"] = 0;
  84.          this.f2 = "wander";
  85.          this.axis = random(10) <= 4 ? "y" : "x";
  86.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  87.          this.speedVar();
  88.          this.getDirString();
  89.       }
  90.       else
  91.       {
  92.          this[this.axis + "MovT"] = 0;
  93.          this.f2 = "gotoXYDest";
  94.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  95.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  96.          this.speedVar();
  97.          if(this.dir == "L" || this.dir == "U")
  98.          {
  99.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  100.          }
  101.          else
  102.          {
  103.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  104.          }
  105.          this.moveScript.splice(0,2);
  106.       }
  107.    }
  108.    function gotoXYDest()
  109.    {
  110.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  111.       {
  112.          if(this.axis == "x")
  113.          {
  114.             this.x = this.xDest;
  115.          }
  116.          else
  117.          {
  118.             this.y = this.yDest;
  119.          }
  120.          this.parseMoveScript();
  121.       }
  122.    }
  123.    function getDirString()
  124.    {
  125.       if(this.xMovT < -1)
  126.       {
  127.          this.dir = "L";
  128.       }
  129.       else if(this.xMovT > 1)
  130.       {
  131.          this.dir = "R";
  132.       }
  133.       else if(this.yMovT > 1)
  134.       {
  135.          this.dir = "D";
  136.       }
  137.       else if(this.yMovT < -1)
  138.       {
  139.          this.dir = "U";
  140.       }
  141.    }
  142.    function evade()
  143.    {
  144.       this.f2 = "wander";
  145.       this[this.axis + "MovT"] = 0;
  146.       this.axis = random(10) <= 4 ? "y" : "x";
  147.       this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  148.       this.speedVar();
  149.       this.getDirString();
  150.    }
  151.    function death()
  152.    {
  153.       _root.stats.destroyed = _root.stats.destroyed + 1;
  154.       _root.stats.score += 1000;
  155.       _root.powerUpB(this.x,this.y,80,"tripleLaserA",3);
  156.       _root.createExploD([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(80,130),_root.randRange(75,100)]);
  157.       var _loc3_ = 0;
  158.       var _loc4_ = random(3);
  159.       while(_loc3_ < _loc4_)
  160.       {
  161.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"batB","",false,true]);
  162.          _loc3_ = _loc3_ + 1;
  163.       }
  164.       _root.audio.playLevel4("batX" + (random(2) + 1),_root.randRange(8,15));
  165.       _root.removeChar("batD" + this.id);
  166.    }
  167.    function death2()
  168.    {
  169.       _root.removeChar("batD" + this.id);
  170.    }
  171.    function wander()
  172.    {
  173.       if(random(100) > 96 + _root.dif.wander)
  174.       {
  175.          this[this.axis + "MovT"] = 0;
  176.          this.axis = this.axis != "x" ? "x" : "y";
  177.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  178.          this.getDirString();
  179.       }
  180.    }
  181.    function main()
  182.    {
  183.       this[this.f2]();
  184.       if(this.oldDir != this.dir)
  185.       {
  186.          this.clip.gotoAndStop("fly" + this.dir);
  187.       }
  188.       this.oldDir = this.dir;
  189.       if(this.nudging)
  190.       {
  191.          this.xA *= 0.5;
  192.          this.yA *= 0.5;
  193.          this.nc = this.nc + 1;
  194.          var _loc8_ = 255 - this.nc * 17;
  195.          this.colorTrans.redOffset = _loc8_ / 2;
  196.          this.trans.colorTransform = this.colorTrans;
  197.          if(this.nc == 15)
  198.          {
  199.             this.xA = this.yA = 0;
  200.             this.nudging = false;
  201.             this.colorTrans.redOffset = this.colorR;
  202.             this.trans.colorTransform = this.colorTrans;
  203.          }
  204.       }
  205.       var _loc4_ = 0;
  206.       var _loc7_ = _root.broShots.length;
  207.       while(_loc4_ < _loc7_)
  208.       {
  209.          var _loc6_ = _root.broShots[_loc4_] + "Clip";
  210.          if(this.clip.hitTest(_root[_loc6_]))
  211.          {
  212.             var _loc3_ = _root.broShots[_loc4_];
  213.             var _loc5_ = this.life;
  214.             this.life -= _root[_loc3_].power;
  215.             if(this.life < 1)
  216.             {
  217.                this.f2 = "death";
  218.             }
  219.             else
  220.             {
  221.                this.nudge(_root[_loc3_].xMov,_root[_loc3_].yMov,10);
  222.                _root.audio.playLevel4("batHit" + (random(2) + 1),_root.randRange(10,20));
  223.             }
  224.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  225.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  226.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  227.             _root[_loc3_].hit(_loc5_);
  228.             break;
  229.          }
  230.          _loc4_ = _loc4_ + 1;
  231.       }
  232.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  233.       {
  234.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  235.          this.f2 = "death";
  236.       }
  237.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  238.       {
  239.          this.f2 = "death2";
  240.       }
  241.       if(this.xMovT < this.xMov)
  242.       {
  243.          this.xMov -= 1;
  244.       }
  245.       else if(this.xMovT > this.xMov)
  246.       {
  247.          this.xMov += 1;
  248.       }
  249.       else
  250.       {
  251.          this.xMov = this.xMovT;
  252.       }
  253.       if(this.yMovT < this.yMov)
  254.       {
  255.          this.yMov -= 1;
  256.       }
  257.       else if(this.yMovT > this.yMov)
  258.       {
  259.          this.yMov += 1;
  260.       }
  261.       else
  262.       {
  263.          this.yMov = this.yMovT;
  264.       }
  265.       this.x += this.xMov + this.xA;
  266.       this.y += this.yMov + this.yA;
  267.       this.clip._x = this.x;
  268.       this.clip._y = this.y;
  269.    }
  270. }
  271.